package nomo.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import nomo.dao.IOderDetailDao;
import nomo.dao.IOrdersDao;
import nomo.model.Orderdetail;
import nomo.model.Orders;
import nomo.model.OrdersDTO;
import nomo.model.vo.OrdersVo;

@RestController
@RequestMapping("orders")
public class OrdersController {
	@Resource
	private IOrdersDao IOrders;
	
	//查询所有订单
    @RequestMapping("findAll.do")
    public Map findAll(OrdersDTO dto) {
      Map map = new HashMap();
      map.put("code", 0);
      map.put("msg", "0");
      map.put("count", IOrders.getCount(dto));
      map.put("data", IOrders.findAll(dto));
      return map;
    }
	
	//根据用户ID查订单
	@RequestMapping("findOrdersByUId.do")
	public Map findOrdersByUId(OrdersDTO dto) {
		List<OrdersVo> list = IOrders.findOrdersByUId(dto);
		Map map = new HashMap();
		map.put("code", "0");
		map.put("msg", "");
		map.put("count", list.size());
		map.put("data", list);
		return map;
	}
	
	@RequestMapping("/findNoDeliverOrders.do")
	@ResponseBody
	public Map findNoDeliverOrders(int oid) {
		Map map=new HashMap();
		map.put("code", 0);
		map.put("count", "100");
		map.put("data", IOrders.findNoDeliverOrders());
		return map;
		
	}
	//发货
	@RequestMapping("/deliver.do")
	@ResponseBody
	public int deliver(int id) {
		return IOrders.deliver(id);
		
	}
	//下订单
	
		@RequestMapping("/addOrders.do")
		@ResponseBody
		public int addOrders(Orders o) {
			return IOrders.addOrders(o);
			
		}
	
	

}
